import React, { Component } from 'react';

import { Table} from 'antd';

import managebox from './index.module.css';


class LogList extends Component {
  state = {
    inpValue: '',
    lesson: '全部',
    school: '全部',
    columns: [
      {
        title: '班级名称',
        dataIndex: 'className',
        key: 'className',
        render: text => <a>{text}</a>
      },
      {
        title: '所属学院',
        dataIndex: 'school',
        key: 'school',
      },
      {
        title: '带班讲师',
        dataIndex: 'teacherid',
        key: 'teacherid',
        render: (value) => (
          this.state.userData && this.state.userData.map(item => {
            if (item.userid == value) {
              return item.name
            }
          })
        )
      },
      {
        title: '课程阶段',
        dataIndex: 'course',
        key: 'course',
      },
      {
        title: '开课日期',
        dataIndex: 'startTime',
        key: 'startTime',
        render: (value) => {
          if (value !== '0') {
         	        return this.getDate(parseInt(value))
         }
         if (value === '0') {
           return '/'
         }	     
        }
      },
	  {
	    title: '结课日期',
	    dataIndex: 'endTime',
	    key: 'endTime',
	    render: (value) => {
	      if (value !== '0') {
	        return this.getDate(parseInt(value))
	      }
	      if (value === '0') {
	        return '/'
	      }
	    }     
	  },
      {
        title: '班级人数',
        dataIndex: 'classType',
        key: 'classType',
      },
    ],
    data: [],
    userData: [],
    teacherid: '未选择',
    coachid: '未选择',
	arr:[]
  }

  
  getDate = (timestamp) => {
    const dates = new Date(timestamp).toLocaleDateString();
    return dates
  }
  render() {
    let { columns, data} = this.state
    return <div className={managebox.B_manageBox}>
			  <div className={managebox.B_content}>
				<div>
				  <Table
					columns={columns}
					dataSource={data}
					pagination={{ pageSize: 4 }}
				  />
				</div>
			  </div>
    </div>
  }

  componentDidMount() {
    this.$httpReq(this.$api.userList(), res => {
      this.setState({ userData: res.data })
    })
		this.$httpReq(this.$api.logList({classid:sessionStorage.id}), res => {
			 this.setState({ arr: res.data })
			 let obj=res.data[0]
			 let newArr=[]
			 newArr.push(obj)
			 this.setState({data:newArr})
		})
  }
}


export default LogList
